
const getMenuString = (val: string, isReplace = false) => {
    if (isReplace) {
        let valString = Number(val?.replace(new RegExp("/"), ""));
        return isNaN(valString)? val : valString;
    }
    var idText: any = getMenuString(val?.substring(val.lastIndexOf("/")), true);
    if (isNaN(idText)) {
        return val
    }
    return val.substring(0, val.lastIndexOf("/"))
}

const getMenuActionParent = (item:any,val: string) => {
    let is = false
    if(item.action){
        item.action.forEach((items:any) => {
            if(items.menu_path == val){
                is = true
            }
        })
    }
    return is;
}
const getItemPath= (children:any) => {
    let menu:any = {};
    if(!children || children.length == 0){
        return children;
    }
    for (let index = 0; index < children.length; index++) {
        menu = children[index];
        if(menu.children && menu.children.length > 0){
            menu = getItemPath(menu.children);
        }
        if(menu.menu_path){
            return menu;
        }
    }
    return children;
}


const toNumber = (str:string) =>{
    return Number(str)
}

export default {
    getMenuString,
    getMenuActionParent,
    getItemPath,
    toNumber
}